package com.wjs.juc.Interrupt;

import java.util.concurrent.TimeUnit;

public class InterruptDemo3 {
    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(() -> {
           while (true){
              if(Thread.currentThread().isInterrupted()){
                  System.out.println("t1线程被打断,中断标识位目前为："+Thread.currentThread().isInterrupted());
                  break;
              }
               try {
                   Thread.sleep(200);
               } catch (InterruptedException e) {
                   Thread.currentThread().interrupt();//没有它就会产生死循环
                   e.printStackTrace();
               }
               System.out.println("t1 ________");
           }
        }, "t1");
        t1.start();
        TimeUnit.SECONDS.sleep(2);
        t1.interrupt();
    }
}
